package Java.ThreadPool;

import java.util.concurrent.*;

//自定义线程池创建
//七个参数  当前线程数量，最大数量，生存时间，类型，阻塞队列，线程工厂，拒绝访问、决策

public class ThreadPoolDemo2 {
    public static void main(String[] args) {
        ExecutorService executorService = new ThreadPoolExecutor(2, 5,
                2L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());


        try {
            //10个顾客请求
            for (int i = 1; i <= 10; i++) {
                //执行
                executorService.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + " 办理业务");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //关闭
            executorService.shutdown();
        }


    }
}
